<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('设备修改')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-device-edit" th:object="${basicDevice}">
            <input name="deviceId" id="deviceId" th:field="*{deviceId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">设备编码</label>
                <div class="col-sm-8">
                    <input name="deviceCode" id="deviceCode" th:field="*{deviceCode}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">安装位置：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="installId" type="hidden" th:field="*{installId}"/>
                        <input class="form-control" type="text" onclick="selectHouseTree()" id="treeName" readonly="true" th:field="*{installAddr}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">安装日期</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input type="text" name="installTime" th:field="*{installTime}" class="form-control" placeholder="安装日期">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">sim卡号</label>
                <div class="col-sm-8">
                    <input name="deviceImei" th:field="*{deviceImei}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">运营商</label>
                <div class="col-sm-8">
                    <select name="operatorType" class="form-control m-b" th:with="type=${@dict.getType('operator_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{operatorType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">设备厂家</label>
                <div class="col-sm-8">
                    <select name="deviceFactory" class="form-control m-b" th:with="type=${@dict.getType('device_factory')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{deviceFactory}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">资费到期</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input type="text" name="endDate" th:field="*{endDate}" class="form-control" placeholder="资费到期">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注</label>
                <div class="col-sm-8">
                    <textarea name="remark" maxlength="500" class="form-control" rows="3">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "basic/device";
        $("#form-device-edit").validate({
            onkeyup: false,
            rules:{
                deviceCode:{
                    remote: {
                        url: prefix + "/checkDeviceCodeUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "deviceCode" : function() {
                                return $.common.trim($("#deviceCode").val());
                            },
                            "deviceId" : function() {
                                return $("#deviceId").val();
                            }
                        }
                    }
                }
            },
            messages: {
                "deviceCode": {
                    remote: "采集设备编码已经存在"
                }
            },
            focusCleanup: true
        });

        /*住房信息-新增-选择父住房信息树*/
        function selectHouseTree() {
            var options = {
                title: '住房信息选择',
                width: "380",
                url: ctx + "basic/house/selectHouseTree/",
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }

        $("input[name='installTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='endDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-device-edit').serialize());
            }
        }
    </script>
    </body>
</html>